#pragma once
#include <comdef.h>
#include <wincred.h>
//  Include the task header file.
#include <taskschd.h>
# pragma comment(lib, "taskschd.lib")
# pragma comment(lib, "comsupp.lib")
# pragma comment(lib, "credui.lib")
class CAutoDianCan
{
public:
	CAutoDianCan(void);
	virtual ~CAutoDianCan(void);
public:
	static tstring& StrReplaceAll(tstring& kSrcStr, const tstring& kOldStr, const tstring& kNewStr);
	static tstring& StrReplaceAllDistinct(tstring& kSrcStr, const tstring& kOldStr, const tstring& kNewStr);
	static tstring& StrTrimLeft(tstring& kSrcStr, const tstring& kTirmChars = L" ");
	static tstring& StrTrimRight(tstring& kSrcStr, const tstring& kTirmChars = L" ");
	static tstring& StrTrim(tstring& kSrcStr, const tstring& kTirmChars = L" ");
	static std::wstring CharToWchar(const std::string& kStr, BOOL bUtf8 = FALSE);
	static std::string WcharToChar(const std::wstring& kWStr, BOOL bUtf8 = FALSE);
	static string AnsiToUtf8(const string& kAnsiStr);
	static string Utf8ToAnsi(const string& kUtf8Str);
	static bool IsSafeUrlChar(char _chCheck);
	static string UrlEncode(const string& _InStr);
	static string UrlDecode(const string& _InStr);
	static CString GetCurWorkPath();
	static CString GetExePath();
	static CString GetFristDrive(UINT _Type = -1, CString kExc = L"");//DRIVE_FIXED

	void ReadIni();
	void SaveIni();
	BOOL IsSettingValid();
public:
	BOOL HttpQuery(
		string& kData,
		string& kRawHeader,
		DWORD& dwStatusCode,
		BOOL bNoRedirect,
		const tstring& kAddHeaders,
		const string& kPostData,
		const tstring& kServerName,
		const tstring& kReqObj,
		WORD wServerPort = INTERNET_DEFAULT_HTTP_PORT,
		const tstring& kAgentName = _T("DianCan 1.0 By zhupf"),
		DWORD dwFlags = 0);

	BOOL HttpsQuery(
		string& kData,
		const tstring& kAddHeaders,
		const string& kPostData,
		const tstring& kServerName,
		const tstring& kReqObj);

	void PreDianCan(BOOL bAuto = TRUE);
	void SyncDianCan(BOOL bAuto = TRUE);
	void AsyncDianCan(BOOL bAuto = TRUE);
	void DoDianCan();
	string GetProblem(vector<string>& kLikes, vector<string>& kProblems);

	BOOL CheckUserNamePassword(string& kLoginKey);
	BOOL LoginInPost(const string& kPostData, string& kLoginKey);
	BOOL GetSessionID(const string& kLoginKey, string& kSessionID);
	BOOL GetTodayMenu(const string& kSessionID, vector<string>& kMenu, BOOL& bAppliedTody);

	string GetErrorMsg();

	bool GZipDecode(const string& kInStr, string& kOutStr);
	bool ZlibDecode(const string& kInStr, string& kOutStr);
	BOOL GetChunkSize(string& kBuffer,int& iChunkSize);
	BOOL ChkFoodAppPage(const string& kSessionID);
	BOOL ChkCanDianApplied(const string& kSessionID);
	BOOL DianCan(const string& kSessionID, const string& kPlace, const string& kSupper, const string& kProblem = "");
	int DoTaskScheduler(wstring kDrive);
	int DoXpTaskScheduler(wstring kDrive);
public:
	static bool s_UrlChars[256];
	string m_kWebDataStr;
	string m_kPlacePosStr;
	string m_kLikeStr;
	BOOL m_bNoSelNoDian;
	string m_kNwTypePosStr;
	string m_kUserNameStr;
	string m_kPasswordStr;
	BOOL m_bAuto;
	CString m_kUserName;
	CString m_kPassword;
	CString m_kPlace;
	CString m_kLike;
};

